package com.itxiuyixiu.homework.entity.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.itxiuyixiu.homework.entity.enums.Sex;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @author 黄磊
 * @date 2020/3/5
 */
@Entity
@Table(indexes = {
        @Index(name = "index_identityCard", columnList = "identityCard", unique = true),
        @Index(name = "index_studentName", columnList = "studentName")})
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
public class Student {
    /**
     * 学号
     */
    @Id
    @Column(length = 9)
    private String studentId;

    /**
     * 密码
     */
    @JsonIgnore
    @Column(nullable = false)
    private String password;

    /**
     * 身份权限
     */
    @Column(nullable = false)
    private String authorities;

    /**
     * 学生姓名
     */
    @Column(nullable = false)
    private String studentName;

    /**
     * 性别
     */
    @Column
    private Sex sex;

    /**
     * 生日
     */
    @Column
    private LocalDate birthday;

    /**
     * 身份证
     */
    @Column(unique = true, nullable = false)
    private String identityCard;

    /**
     * 入学年份
     */
    @Column
    private String startYear;

    /**
     * 班级
     */
    @Column
    private String studentClass;

    /**
     * 联系方式
     */
    @Column
    private String studentContact;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fk_academy_id")
    private Academy academy;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fk_major_Id")
    private Major major;

    private LocalDateTime gmtCreated;

    private LocalDateTime gmtModified;

    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAuthorities() {
        return authorities;
    }

    public void setAuthorities(String authorities) {
        this.authorities = authorities;
    }

    public void addAuthorities(String authorities) {
        this.authorities = "," + authorities;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public Sex getSex() {
        return sex;
    }

    public void setSex(Sex sex) {
        this.sex = sex;
    }

    public LocalDate getBirthday() {
        return birthday;
    }

    public void setBirthday(LocalDate birthday) {
        this.birthday = birthday;
    }

    public String getIdentityCard() {
        return identityCard;
    }

    public void setIdentityCard(String identityCard) {
        this.identityCard = identityCard;
    }

    public String getStartYear() {
        return startYear;
    }

    public void setStartYear(String startYear) {
        this.startYear = startYear;
    }

    public String getStudentClass() {
        return studentClass;
    }

    public void setStudentClass(String studentClass) {
        this.studentClass = studentClass;
    }

    public String getStudentContact() {
        return studentContact;
    }

    public void setStudentContact(String studentContact) {
        this.studentContact = studentContact;
    }

    public Academy getAcademy() {
        return academy;
    }

    public void setAcademy(Academy academy) {
        this.academy = academy;
    }

    public Major getMajor() {
        return major;
    }

    public void setMajor(Major major) {
        this.major = major;
    }

    public LocalDateTime getGmtCreated() {
        return gmtCreated;
    }

    public void setGmtCreated(LocalDateTime gmtCreated) {
        this.gmtCreated = gmtCreated;
    }

    public LocalDateTime getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(LocalDateTime gmtModified) {
        this.gmtModified = gmtModified;
    }
}
